package bma.common.langutil.jmshell.cmdopt;


/**
 * Thrown when an illegal or missing value is given by the user for an option
 * that takes a value. <code>getMessage()</code> returns an error string
 * suitable for reporting the error to the user (in English).
 * 
 * No generic class can ever extend <code>java.lang.Throwable</code>, so we have
 * to return <code>Option&lt;?&gt;</code> instead of
 * <code>Option&lt;T&gt;</code>.
 */
public class IllegalOptionValueException extends OptionException {

	private static final long serialVersionUID = 1L;

	public <T> IllegalOptionValueException(Option<T> opt, String value) {
		super("Illegal value '" + value + "' for option "
				+ (opt.shortForm() != null ? "-" + opt.shortForm() + "/" : "")
				+ "--" + opt.longForm());
		this.option = opt;
		this.value = value;
	}

	/**
	 * @return the name of the option whose value was illegal (e.g. "-u")
	 */
	public Option<?> getOption() {
		return this.option;
	}

	/**
	 * @return the illegal value
	 */
	public String getValue() {
		return this.value;
	}

	private final Option<?> option;
	private final String value;
}